using Quickly.Certs.Core;
using Quickly.Certs.EntityFrameworkCore;
using Quickly.Certs.WebApi;
using Quickly.Certs.WebApi.Endpoints;
using Quickly.SpaProxy;
using Scalar.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

builder.Configuration.AddEnvironmentVariables("QUICKCERTS_");
builder.Configuration.ConfigureAgileConfigIfExists();

// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services
    .AddOpenApi()
    .AddHttpContextAccessor();

builder.Services
    .AddAlibabaCloudOptions()
    .AddDbContextQuickly<CertsContext>("Default")
    .AddCertsStoreQuickly();

builder.Services
    .AddCertsCoreQuickly()
    .AddCertsPersistence(builder.Configuration);

builder.Services.AddCors();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.MapScalarApiReference();
    app.MapOpenApi();
}

//app.UseHttpsRedirection();
app.UseHsts();
app.UseCors();

app.UseStaticFiles();
app.UseFileServer();

app.MapManagementEndpoints();

app.UseSpaProxyDevelopmentReverseProxy();

app.Run();
